<template>
  <div>
    <div class="outlogin" @click="outLogin">退出登录</div>
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  methods: {
    // 退出登录
    outLogin() {
      // 删除清空token
      localStorage.removeItem("x-auth-token");
      localStorage.clear();
      // 提示
      this.$store.dispatch("asyncclosetoast", {
        content: "你以退出，即将返回首页",
        icon: "success",
      });
      // 2秒后跳去首页
      setTimeout(() => {
        this.$router.push("/home");
        this.$router.go(0);
      }, 2000);
    },
  },
};
</script>
 
<style lang = "less" scoped>
.outlogin {
  width: 100px;
  background-color: blue;
  height: 50px;
  color: #fff;
  text-align: center;
  line-height: 50px;
  border-radius: 10px;
  cursor: pointer;
}
</style>